//厨房操作handerKitchen
function handerKitchen(){
    for(let i = point; i < cookingList.length;i++){
        if(cookingList[i].status !=="wait"){
            continue;
        }
        let fooID = cookingList[i].foodID;
        let foodName = dishes[fooID].name;
        let colorID = cookingList[i].colorId;
        //找到空闲的厨师
        for(let j in chef){
            if(chef[j].status === "free"){
                cookingList[i].status ="ing";
                let firstColor = 0;
                let secondColor =120;
                if( j > 1){
                    //正在炒菜的厨师不能将其解雇，同时不能将第一第二个进行解雇
                    let broEle =getClassName("fireCooker")[j-1];
                    broEle.style.display = "none";
                }
                //改变其的背景颜色
                let parEle =getClassName("chef")[j];
                let curEle =getClassName("chef-icon")[j];
                let background = "background: linear-gradient(-90deg, #" + color[colorID].color1 + " 50%, #" + color[colorID].color2 + " 50%);";
                curEle.setAttribute("style", background);
                //添加food的煮菜列表
                let foodNameDiv = document.createElement("div");
                let id = "cookFood" + date.getHours() + "" + date.getMinutes() + "" + date.getSeconds() + "" + i;
                foodNameDiv.className = "cookFood";
                foodNameDiv.id = id;
                //将名字插入到div中
                foodNameDiv.innerHTML = foodName;
                let backgroundColor = "background-color:#" + color[colorID].color2 + ";";
                foodNameDiv.setAttribute("style", backgroundColor);
                parEle.appendChild(foodNameDiv);
                chef[j].status = "busy";//将厨师设置为忙碌的状态
                if (cookCount > 0) { //如果还有未做的菜
                    handerKitchen();
                }
                let timer = setInterval(() => { //厨师做菜时间
                    firstColor += cookingChange;
                    secondColor -= cookingChange;//设置煮菜的进度条
                    let ele = $(id);
                    let background = "background: linear-gradient(-90deg, #" + color[colorID].color2 + " " + secondColor + "%, #" + color[colorID].color1 + " " + "0,#" + color[colorID].color1 + " " + firstColor + "%)";
                    ele.setAttribute("style", background);
                    if (firstColor === 120) { //菜做好了
                        cookCount--; //未做数量减少一个
                        point++; //指针前进一步
                        cookingList[i].status = "finish";
                        finishCookList.push(cookingList[i]); //先进先出
                        chef[j].status = "free";
                        background = "background: linear-gradient(-90deg, #aaa 50%, #ddd 50%);";
                        curEle.setAttribute("style", background);
                        if (j > 1) { // 隐藏厨师的解雇按钮。厨师做菜时不能解雇&&第一个厨师不能解雇
                            let broEle =getClassName("fireCooker")[j - 1];
                            broEle.style.display = "block";
                        }
                        let foodDiv = $(id);
                        //消失进度条东西
                        foodDiv.setAttribute("style", "display:none;");
                        clearInterval(timer);
                    }
                }, cookingTime / 5);
                break;
            }
        }
    }
}
// //删除厨师
function deleteChef(chefID){
    fireDiv.style.display="flex";
    let newStyle = ".bar div{padding:0 2rem}"
    addStyle(newStyle);
    let yes_btn = $("sure-fire-btn");
    let not_btn = $("not-fire-btn");
    const fireChefButtonLisenrerT=()=>{
        comfirmFireBtn(chefID);
    }
    yes_btn.removeEventListener("click",fireChefButtonListener);
    yes_btn.addEventListener("click",fireChefButtonLisenrerT);
    fireChefButtonListener = fireChefButtonLisenrerT;
    not_btn.addEventListener("click",quitFireBtn);
}
//不确认解除厨师的按钮
function quitFireBtn(){
    fireDiv.style.display ="none";
    removeStyle();
}

//确认解除厨师的按钮
function comfirmFireBtn(chefID) {
    //确认解除该厨师，首先要判断其解雇的违约金够不够，不够则不行
    let income = $("all_momey");
    let remainMoney = parseInt(income.innerHTML);
    if(remainMoney < 140){
        ElMessage("warning","你的金额不足以支付解压金,请稍后再尝试",1500);
    }else{
        fireDiv.style.display = "none";
        if (chefNumber ===3) {
            removeStyle();//删除厨师的时候两行的厨师列表变为一行
        }
        let cookDiv = $("cook");
        let removeChefDiv = $(chefID);
        cookDiv.removeChild(removeChefDiv.parentNode);
        ElMessage("remind","解约厨师成功，解约指出￥140",1500);
        remainMoney -= 140;
        income.innerHTML = remainMoney;
        let chefIndex = chefID.split("_")[1];
        //分割出当前是第几个的厨师，然后将初始列表里面的该元素删除
        delete chef[chefIndex];
        //厨师的数目删除
        chefNumber--;
    }
}
/*放弃添加厨师*/
function quitAddBtn() {
    addChefPage.style.display = "none";
    removeStyle();
}
